﻿using System;
using System.Linq;
using SportTraining.Core.Dal;
using SportTraining.Core.Domain;

namespace SportTraining.Core.Linq2Sql.Dal
{
    public class SectionDal : BaseDal, ISectionDal
    {
        public SectionDal(IDataContext dataContext) : base(dataContext)
        {
        }

        
        #region Implementation of IBaseDal<ISection>

        public ISection GetById(int id)
        {
            return dataContext.Sections.FirstOrDefault(item => item.Id == id);
        }

        public void Add(ISection entity)
        {
            if (!(entity is Section))
            {
                throw new ArgumentException("Bad Section class");
            }

            dataContext.Sections.InsertOnSubmit((Section)entity);
        }

        public void Delete(ISection entity)
        {
            if (!(entity is Section))
            {
                throw new ArgumentException("Bad Section class");
            }

            dataContext.Sections.DeleteOnSubmit((Section)entity);
        }

        public IQueryable<ISection> SelectAll()
        {
            return dataContext.Sections;
        }
        #endregion
    }
}
